Framework EDI Reference. Methods and Properties
ediSecurities. ExportCertificatePfx

Exports a certificate from the default certificate store to a PFX file.

Syntax:

Parameters:

Returns:

Returns 1 if the operation is successful; otherwise returns 0 if the operation fails.

Remarks:

The sSubjectName, sIssuerName and sHexSerialNumber are used to search for the certificate in the certificate store.  See Locating a Digital Certificate.

If fExportPrivateKey is TRUE, the private key is packaged with the certificate in the PFX file.  If this flag is TRUE and the private key of the certificate does not exist then an error is generated.  If fExportPrivateKey is FALSE, only the certificate is exported to the PFX file whether the private key exists for it or not.

The sServiceProvider and lProviderType specify the CSP database where the private key container is stored.  If fExportPrivateKey is TRUE, and the key container is not found in the CSP database, an error is generated.  If sServiceProvider and/or lProviderType are not specified, the default CSP database is used, which is specified by DefaultProviderName and ServiceProviderType .

The default certificate store is specified by the properties DefaultCertSystemStoreName and DefaultCertSystemStoreLocation.

Example:

Dim oEdiDoc As Fredi.ediDocument
Dim oSecurities As Fredi.ediSecurities

' Create instance of Framework EDI.
Set oEdiDoc = New Fredi.ediDocument

' Get securities object.
Set oSecurities = oEdiDoc.GetSecurities

' Set the default certificate store
oSecurities.DefaultCertSystemStoreName = "My" ' Case sensitive

' Set the default certificate store location
oSecurities.DefaultCertSystemStoreLocation = "CurrentUser"

' Export test certificate to PFX file.
' Password of PFX file is PASS123.
' Private Key is exported with certificate.
If oSecurities.ExportCertificatePfx("Edidev Test Certificate", "Edidev Test Certificate", "", "PASS123", True, App.Path & "\MyExportedTestCert.PFX") = 1 Then
MsgBox "Successfully exported test certificate 'Edidev Test Certificate' to PFX file MyExportedTestCert.PFX."

Else
MsgBox "Failed to create certificate"

End If

Sample

M_ExportCertificatePfx.zip